package  
{
	import net.flashpunk.Entity;
	import net.flashpunk.FP;
	/**
	 * © 2012 TheJavaArcade.com
	 */	
	public class Exit extends Entity {
		
		private var theExit:String;
		private var theWorld:GameEngine;
		
		public function Exit(exitStr:String, world:GameEngine) {
			type = "exit";
			theExit = exitStr;
			theWorld = world;
			if (theExit == "East") {
				x = 1200;
				y = 0;
				setHitbox(8, 720, 0,0);
			}
			if (theExit == "West") {
				x = -8;
				y = 0;
				setHitbox(8, 720, 0,0);
			}
			if (theExit == "North")	{
				x = 0;
				y = -8;
				setHitbox(1200, 8, 0,0);
			}
			if (theExit == "South")	{
				x = 0;
				y = 720;
				setHitbox(1200, 8, 0,0);
			}
			
		}
		
		override public function update():void {//transitions from world to world
			if (collide("fracas", x, y)) {
				if (GameEngine.level == 0 && theExit == "South") { theWorld.loadLevel(GameEngine.fracas.x, 1, 1, 0); return; }
				if (GameEngine.level == 0 && theExit == "West") { theWorld.loadLevel(1178, GameEngine.fracas.y, 10, 0); return; }
				if (GameEngine.level == 1 && theExit == "North") { theWorld.loadLevel(GameEngine.fracas.x, 690, 0, 1); return; }
				if (GameEngine.level == 1 && theExit == "East") { theWorld.loadLevel(1, GameEngine.fracas.y, 2, 1); return; }
				if (GameEngine.level == 1 && theExit == "West") { theWorld.loadLevel(1178, GameEngine.fracas.y, 3, 1); return; }
				if (GameEngine.level == 2 && theExit == "West") { theWorld.loadLevel(1178, GameEngine.fracas.y, 1, 2); return; }
				if (GameEngine.level == 2 && theExit == "East") { theWorld.loadLevel(1, GameEngine.fracas.y, 4, 2); return; }
				if (GameEngine.level == 3 && theExit == "East") { theWorld.loadLevel(1, GameEngine.fracas.y, 1, 3); return; }
				if (GameEngine.level == 4 && theExit == "West") { theWorld.loadLevel(1178, GameEngine.fracas.y, 2, 4); return; }
				if (GameEngine.level == 4 && theExit == "South") { theWorld.loadLevel(GameEngine.fracas.x, 1, 5, 4); return; }				
				if (GameEngine.level == 5 && theExit == "North") { theWorld.loadLevel(GameEngine.fracas.x, 690, 4, 5); return; }
				if (GameEngine.level == 5 && theExit == "South") { theWorld.loadLevel(GameEngine.fracas.x, 1, 6, 5); return; }
				if (GameEngine.level == 5 && theExit == "West") { theWorld.loadLevel(1178, GameEngine.fracas.y, 7, 5); return; }
				if (GameEngine.level == 6 && theExit == "North") { theWorld.loadLevel(GameEngine.fracas.x, 690, 5, 6); return; }
				if (GameEngine.level == 7 && theExit == "East") { theWorld.loadLevel(1, GameEngine.fracas.y, 5, 7); return; }
				if (GameEngine.level == 7 && theExit == "West") { theWorld.loadLevel(1178, GameEngine.fracas.y, 8, 7); return; }
				if (GameEngine.level == 8 && theExit == "East") { theWorld.loadLevel(1, GameEngine.fracas.y, 7, 8); return; }
				if (GameEngine.level == 8 && theExit == "North") { theWorld.loadLevel(GameEngine.fracas.x, 690, 9, 8); return; }
				if (GameEngine.level == 9 && theExit == "South") { theWorld.loadLevel(GameEngine.fracas.x, 1, 8, 9); return; }
				if (GameEngine.level == 9 && theExit == "North") { theWorld.loadLevel(GameEngine.fracas.x, 690, 10, 9); return; }
				if (GameEngine.level == 10 && theExit == "South") { theWorld.loadLevel(GameEngine.fracas.x, 1, 9, 10); return; }
				if (GameEngine.level == 10 && theExit == "East") { theWorld.loadLevel(1, GameEngine.fracas.y, 0, 10); return; }
			}
		}
	}

}